package com.herysoft.scm.log;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

public class UserAuthenticationFailureHandler implements
		AuthenticationFailureHandler {
	private String url;
	public void setUrl(String url) {
		this.url = url;
	}
	Logger log=Logger.getLogger(this.getClass());
	public void onAuthenticationFailure(HttpServletRequest request,
			HttpServletResponse response, AuthenticationException ex)
			throws IOException, ServletException {
		log.info(ex.getAuthentication().getName()+"["+request.getRemoteAddr()+"] login failure!");
		response.sendRedirect(request.getContextPath()+url);
	}

}
